package com.example.demo.service.impl;

import com.example.demo.mapper.StudentMapper;
import com.example.demo.pojo.PageResult;
import com.example.demo.pojo.QueryString;
import com.example.demo.pojo.Student;
import com.example.demo.service.StudentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
@Autowired
private StudentMapper studentMapper;
    @Override
    public PageResult page(QueryString querystring) {

        PageHelper.startPage(querystring.getPage(),querystring.getPageSize());

        Page<Student> s = studentMapper.list(querystring);

        return  new PageResult(s.getTotal(),s.getResult());
    }

    @Override
    public void delete(List<Integer> ids) {
         studentMapper.delete(ids);
    }

    @Override
    public void save(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        student.setCreateTime(LocalDateTime.now());
         studentMapper.save(student);
    }

    @Override
    public Student selectId(Integer id) {

        Student s=studentMapper.select(id);
        return s;
    }

    @Override
    public void update(Student s) {
        s.setUpdateTime(LocalDateTime.now());
        studentMapper.update(s);
    }

    @Override
    public void right(Integer id, Integer score) {
        studentMapper.right(id,score);
    }
}
